/**
 * @param {number[]} arr
 * @return {number}
 */
var sumSubarrayMins = function (arr) {
  const mod = Math.pow(10,9)+7
  let count = 0
  let pre = []
  let left = 0
  let right = left + 1
  while (left < arr.length) {
    count += arr[left]
    pre = [].concat([arr[left]])
    while (right != arr.length) {
      pre.push(arr[right])

      count += Math.min(...pre)
      right++
    }
    left++
    right = left + 1
  }
  return count % mod
}
console.log(sumSubarrayMins([11,81,94,43,3]))
